<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">

      <el-form-item label="电影编号">
        <el-input disabled v-model="form.nfId" />
      </el-form-item>
      <el-form-item label="电影名">
        <el-input v-model="form.nfName" />
      </el-form-item>
      <el-form-item label="演员名">
        <el-input v-model="form.nfActor" />
      </el-form-item>
      <el-form-item label="电影图地址">
        <el-input disabled v-model="form.nfImg" />
      </el-form-item>
      <el-form-item label="价格">
        <el-input v-model="form.nfPrice" />
      </el-form-item>
      <el-form-item label="时长">
        <el-input v-model="form.nfLongtime" />
      </el-form-item>
      <el-form-item label="导演">
        <el-input v-model="form.nfDirector"  />
      </el-form-item>
      <el-form-item>
      <el-form-item label="是否在首页显示">
        <el-select v-model="form.nfIshow" placeholder="是">
          <el-option label="是" value="1" />
          <el-option label="否" value="0" />
        </el-select>
      </el-form-item>
        <el-form-item label="电影是否上映">
          <el-select v-model="form.nfChangeon" placeholder="否">
            <el-option label="是" value="1" />
            <el-option label="否" value="0" />
          </el-select>
        </el-form-item>

        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Qs from 'qs'
export default {
  data() {
    return {
      form: {
        nfId: 1, id: 1, nfName: '', nfDirector: '', nfActor: '', nfLongtime: '', nfPrice: 20, nfImg: '', nfIshow: 1, nfChangeon: 1
      },
      nfId: this.$route.params.nfId
    }
  },
  created() {
    this.getfilm()
  },
  methods: {
    onSubmit() {
      var vm =this
      this.$confirm('此操作将修改该电影信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios({
          url:'http://localhost:80/api/nextfilm/updata',
          method:'post',
          transformRequest: [function (data) {
            return Qs.stringify(data)
          }],
          data:vm.form
        }).then(function(res) {
          if (res.data.success){
            vm.$message('成功!')
            console.log(res.data)
            vm.$router.push({name:'nextfilm'})
          }else{
            vm.$message('失败!')
            console.log(res.data)
          }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    },
    getfilm() {
      var vm = this
      this.axios({
        url: 'http://localhost:80/api/nextfilm/getfilm/' + this.nfId
      }).then(function(res) {
        if (res.data.success) {
          vm.form = res.data.data
        }
      })
    }
  } ,

}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

